﻿//
package ICode.name.ui {
	//
	import flash.display.Bitmap ;
	import flash.display.BitmapData ;
	import flash.geom.Rectangle ;
	import flash.geom.Point ;
	//
	public class BigBitmapData extends BitmapData{
		//
		private var m_arrData:Array ;
		private var m_nLines:int = 0;
		private var m_nColumns:int = 0 ;
		private var m_nWidth:int = 0;
		private var m_nHeight:int = 0 ;
		private var m_nCellWidth:int = 0 ;
		private var m_nCellHeight:int = 0;
		private var m_nOfsetX:int = 0;
		private var m_nOfsetY:int = 0 ;
		//
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥构造函数
		public function BigBitmapData(transparent:Boolean = true, fillColor:uint = 0xFFFFFFFF ){
			super(2880,2880,transparent,fillColor );
		}
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥数据滚动函数
		public override function scroll(x:int, y:int):void {
			x = Math.max(x, 0),y = Math.max(y,0);
			if(m_arrData!=null){
				m_nOfsetX = x , m_nOfsetY = y ;
				var ofsetX:int =  x % m_nCellWidth ;
				var ofsetY:int =  y % m_nCellHeight ;
				var lineNumber:int = y / m_nCellHeight ;
				var columnNumber :int = x /m_nCellWidth ;
				//∥∥∥∥∥∥∥∥∥∥∥∥∥∥
				var xTimes:int = Math.ceil(m_nWidth / m_nCellWidth ) + 1;
				var yTimes:int = Math.ceil(m_nHeight / m_nCellHeight ) + 1;
				for(var i:uint = 0 ;i<yTimes ;i++ ){
					var arr:Array = m_arrData[lineNumber + i] ;
					if(arr!=null){
						for(var j:uint = 0;j<xTimes;j++ ){
							var bmd:BitmapData = arr[columnNumber + j] as BitmapData ;
							if(bmd!=null){
								var rect:Rectangle = new Rectangle(ofsetX , ofsetY , m_nCellWidth - ofsetX , m_nCellHeight - ofsetY );
								var point:Point = new Point(m_nCellWidth * j , m_nCellHeight * i);
								if(i>0){
									point.y = m_nCellHeight * i - rect.y ;
									rect.y = 0;
									rect.height = m_nCellHeight ;
								}
								if(j>0){
									point.x = m_nCellWidth * j - rect.x ;
									rect.x = 0 ;
									rect.width = m_nCellWidth ;
								}
								super.copyPixels(bmd,rect,point );
							}
						}
					}
				}
			}
		}
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥偏移获取函数
		public function get ofsetX():int{return m_nOfsetX };
		public function get ofsetY():int{return m_nOfsetY } ;
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥尺寸设置函数
		public function set width(value:int):void{m_nWidth = value }
		public function set height(value:int):void{m_nHeight = value };
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥尺寸获取函数
		public override function get width():int{return m_nWidth } ;
		public override function get height():int{return m_nHeight } ;
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥总体尺寸函数
		public function get dataWidth():int{return m_nCellWidth * m_nColumns } ;
		public function get dataHeight():int{return m_nCellHeight * m_nLines } ;
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥数据添加函数
		public function set data(arr:Array):void {
			m_arrData = arr ;
			if(arr!=null){
				m_nLines = arr.length ;
				for(var i:uint= 0 ;i<arr.length; i++ ){
					var subArr:Array = arr[i] as Array;
					if(subArr!=null){
						if(i==0){
							m_nColumns = subArr.length ;
							if(m_nColumns ){
								var obj:BitmapData = subArr[0] as BitmapData ;
								if(obj!=null){
									m_nCellWidth = obj.width ;
									m_nCellHeight = obj.height ;
								}
							}
						}else{
							if(subArr.length<m_nColumns){
								m_nColumns = subArr.length ;
							}
						}
					}
				}
			}
		}
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥
	}
}